/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroMarca.java
 *
 * Created on 05/04/2011, 01:19:36
 */
package Tela;

import Classe.BD;
import Classe.Marca;
import Classe.Validacao;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author gladson
 */
public class CadastroMarca extends Validacao {

    private Component frameI;

    /** Creates new form CadastroMarca */
    public CadastroMarca() {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }
    CadastroVeiculo vc;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jpnCadastroMarca = new javax.swing.JPanel();
        btSalvarMarca = new javax.swing.JButton();
        btSairMarca = new javax.swing.JButton();
        lblMensagemMarca = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lblMarcaMarca = new javax.swing.JLabel();
        sTxtMarca = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jpnCadastroMarca.setBackground(new java.awt.Color(255, 255, 255));
        jpnCadastroMarca.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Cadastro Marca ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N

        btSalvarMarca.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        btSalvarMarca.setText("Salvar");
        btSalvarMarca.setToolTipText("Salvar");
        btSalvarMarca.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSalvarMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarMarcaActionPerformed(evt);
            }
        });

        btSairMarca.setFont(new java.awt.Font("Arial", 0, 12));
        btSairMarca.setText("Sair");
        btSairMarca.setToolTipText("Sair");
        btSairMarca.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSairMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairMarcaActionPerformed(evt);
            }
        });

        lblMensagemMarca.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblMensagemMarca.setForeground(new java.awt.Color(244, 6, 6));

        jButton1.setText("Limpar");
        jButton1.setToolTipText("Limpar");
        jButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lblMarcaMarca.setFont(new java.awt.Font("Arial", 1, 11));
        lblMarcaMarca.setText("Marca");

        sTxtMarca.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jpnCadastroMarcaLayout = new javax.swing.GroupLayout(jpnCadastroMarca);
        jpnCadastroMarca.setLayout(jpnCadastroMarcaLayout);
        jpnCadastroMarcaLayout.setHorizontalGroup(
            jpnCadastroMarcaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnCadastroMarcaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnCadastroMarcaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMensagemMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                    .addGroup(jpnCadastroMarcaLayout.createSequentialGroup()
                        .addComponent(btSalvarMarca)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(btSairMarca))
                    .addComponent(lblMarcaMarca)
                    .addComponent(sTxtMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE))
                .addContainerGap())
        );

        jpnCadastroMarcaLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btSairMarca, btSalvarMarca, jButton1});

        jpnCadastroMarcaLayout.setVerticalGroup(
            jpnCadastroMarcaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnCadastroMarcaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMensagemMarca)
                .addGap(18, 18, 18)
                .addComponent(lblMarcaMarca)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sTxtMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addGroup(jpnCadastroMarcaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSairMarca)
                    .addComponent(jButton1)
                    .addComponent(btSalvarMarca))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpnCadastroMarcaLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btSairMarca, btSalvarMarca, jButton1});

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpnCadastroMarca, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpnCadastroMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-524)/2, (screenSize.height-244)/2, 524, 244);
    }// </editor-fold>//GEN-END:initComponents

    private void btSairMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairMarcaActionPerformed
        this.dispose();
}//GEN-LAST:event_btSairMarcaActionPerformed

    private void btSalvarMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarMarcaActionPerformed
        if (validar()) {

            try {
                Marca marca = new Marca();
                marca.setNomeMarca(sTxtMarca.getText().toUpperCase());


                String sql = "insert into marca values (sq_marca.nextval,?)";

//Object[] parametros = new Object[0];//para criar um vetor vazio e poder colocar todos as variaveis no select

                Object[] parametros = {marca.getNomeMarca()};
                Object[] tipos = {String.class};

                BD banco = new BD();
                banco.executar(sql, parametros, tipos);
                JOptionPane.showMessageDialog(frameI, "Cadastro salvo com Sucesso");
                sTxtMarca.setText("");

                this.vc.iniciar();
            } catch (Exception ex) {
            }

        }

    }//GEN-LAST:event_btSalvarMarcaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        sTxtMarca.setText("");
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroMarca().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btSairMarca;
    private javax.swing.JButton btSalvarMarca;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jpnCadastroMarca;
    private javax.swing.JLabel lblMarcaMarca;
    private javax.swing.JLabel lblMensagemMarca;
    private javax.swing.JTextField sTxtMarca;
    // End of variables declaration//GEN-END:variables

    public void pegar(CadastroVeiculo cv) {
        this.vc = cv;
    }

    public boolean validar() {
        boolean Resultado = true;



        if (validarMarca(sTxtMarca.getText().trim()) == false) {
            Resultado = false;
        }

        return Resultado;
    }
}
